fix: support openai SDK v2 — wrap parse() on non-beta path, isolate wrapper errors#1326
Open
serhiizghama wants to merge 1 commit intoAgentOps-AI:mainfrom
Open
Conversation
In openai >= 2.0, the structured output .parse() method moved from openai.resources.beta.chat.completions to openai.resources.chat.completions. The old code wrapped all methods in a single try/except, so a ModuleNotFoundError on the beta path would silently skip the Responses API wrappers too. Changes: - Try chat.completions.parse first (current SDK location) - Fall back to beta.chat.completions.parse for openai < 2.0 compatibility - Split into separate try/except blocks so a failure in one group doesn't prevent other wrappers (e.g. Responses API) from being installed Fixes AgentOps-AI#1260
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In openai >= 2.0, the structured output
.parse()method moved fromopenai.resources.beta.chat.completionstoopenai.resources.chat.completions. The current instrumentor always tries the beta path, which raisesModuleNotFoundError: No module named 'openai.resources.beta.chat'on newer SDK versions.A secondary issue: all wrappers are in a single
try/except, so when the beta path fails, the Responses API wrappers (openai.resources.responses) are silently skipped too — meaning users on openai v2 lose both structured output tracing and Responses API tracing.Closes #1260
Changes
chat.completions.parsefirst (current SDK location in openai >= 2.0)beta.chat.completions.parsefor backwards compatibility with openai < 2.0try/exceptblocks so a failure in one wrapper group (e.g. beta path) doesn't prevent other wrappers from being installedTesting
Install
agentopswithopenai >= 2.0and verify:[OPENAI INSTRUMENTOR] Error setting up OpenAI streaming wrappers: No module named 'openai.resources.beta.chat'warning on startup.parse()are traced correctlyAlso tested with
openai < 2.0to confirm backwards compatibility via the legacy beta fallback path.